package com.ssm.controller.agency;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.ssm.controller.BaseController;
import com.ssm.entity.agency.AgencyEntity;
import com.ssm.service.agency.AgencyService;
import com.ssm.utils.ResultType;
import com.ssm.utils.StatusCode;

/**
 * 经销商用户controller
 * @author around
 * @date 2017-6-14
 */
@Controller
@RequestMapping("/agency")
public class AgencyController extends BaseController {

	@Autowired
	private AgencyService agencyService;
	
	/**
	 * 经销商详情页信息封装查询
	 * @param request
	 * @param session
	 * @param agency
	 * @return String 
	 */
	@RequestMapping(value = "/detail", method = {RequestMethod.POST, RequestMethod.GET})
	@ResponseBody
	public void detail(HttpServletRequest request, HttpServletResponse response, 
			AgencyEntity agency) {
		if (null == agency.getId()) {
			doResult(response, false, StatusCode.FINDERROR, null, "缺少经销商ID");
			return;
		}
		try {
			agency = agencyService.find(agency.getId());
			if(null == agency)
				doResult(response, false, StatusCode.FINDERROR, null, "查询失败");
			else
				doResult(response, true, StatusCode.FINDSUCCESS, agency, "查询成功");
		} catch (Exception e) {
			doResult(response, false, StatusCode.FINDERROR, null, "查询错误");
			e.printStackTrace();
		}
	}
	
	
}
